package com.uenpay.oem.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.socks.library.KLog;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.im.utilities.Toasts;
import com.uenpay.oem.R;
import com.uenpay.oem.common.AppConstant;
import com.uenpay.oem.data.bean.UserAuthInfo;
import com.uenpay.oem.data.bean.UserIdCardInfo;
import com.uenpay.oem.data.model.ITransactionModel;
import com.uenpay.oem.data.model.IUserAuthModel;
import com.uenpay.oem.data.modelImpl.BankCardModel;
import com.uenpay.oem.data.modelImpl.TransactionModel;
import com.uenpay.oem.data.modelImpl.UserAuthModel;
import com.uenpay.service.bean.BankCardInfo;
import com.uenpay.service.bean.TransBankCardList;
import com.uenpay.util.app.base.BaseActivity;
import com.uenpay.util.net.listener.HttpOnNextListener;
import com.uenpay.util.net.listener.HttpResultListener;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by PS on 2016/11/21.
 */

@Route(path = "/test/test")
public class TestActivity extends BaseActivity {
    BankCardModel mBankCardModel;
    IUserAuthModel mUserAuthModel;
    ITransactionModel mTranscationModel;

    private UserIdCardInfo mUserIdCardInfo = null;
    private BankCardInfo mBankCardInfo = null;
    @BindView(R.id.et_code)
    EditText etCode;

    String tradeNo;
    String wkPayNo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getIntent() != null) {
            tradeNo = getIntent().getStringExtra("tradeNo");
            wkPayNo = getIntent().getStringExtra("wkPayNo");
        }
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.test_layout;
    }

    @Override
    public void initView(View view) {
        mBankCardModel = new BankCardModel();
        mUserAuthModel = new UserAuthModel();
        mTranscationModel = new TransactionModel();
    }

    @OnClick(R.id.button)
    public void button() {
        mBankCardModel.getUserBankList(new HttpOnNextListener<List<BankCardInfo>>() {
            @Override
            public void onNext(List<BankCardInfo> bankCardInfos) {
                KLog.d(bankCardInfos.size());
            }
        });
    }

    @OnClick(R.id.button1)
    public void button1() {
        mBankCardModel.userBankCardBinSelect("6225757545259278", new HttpOnNextListener<BankCardInfo>() {
            @Override
            public void onNext(BankCardInfo bankCardInfo) {
                if (bankCardInfo != null) {
                    mBankCardInfo = bankCardInfo;
                    Toasts.shortToast(TestActivity.this, "银行卡信息获取成功");
                    KLog.d(bankCardInfo.toString());
                }
            }
        });
    }

    @OnClick(R.id.button2)
    public void button2() {
        BankCardInfo cardInfo = new BankCardInfo();
       /* cardInfo.setBankName("招商银行");
        cardInfo.setBankNo("03080000");
        cardInfo.setCardNo("6216910209821146");
        cardInfo.setUserName("刘楼");
        cardInfo.setCardType("1");
        cardInfo.setExpireDate("");
       cardInfo.setPhone("13397380887");
        cardInfo.setCvvCode("");*/
        if (mBankCardInfo != null) {
            mBankCardModel.saveUserBank(mBankCardInfo, new HttpResultListener() {
                @Override
                public void onComplete() {
                    super.onComplete();
                    Toasts.shortToast(TestActivity.this, "添加成功");
                    KLog.d(TAG, "saveUserBank complete");
                }
            });
        }
    }

    @OnClick(R.id.button3)
    public void button3() {
        mBankCardModel.relieveUserBankDetail("9", 0, new HttpResultListener() {
            @Override
            public void onComplete() {
                super.onComplete();
                KLog.d(TAG, "relieveUserBankDetail complete");
            }
        });
    }

    @OnClick(R.id.button4)
    public void button4() {
        mBankCardModel.recognitionUserBank("", new HttpOnNextListener<BankCardInfo>() {
            @Override
            public void onNext(BankCardInfo bankCardInfo) {
                if (bankCardInfo != null) {
                    KLog.d(bankCardInfo.toString());
                }
            }
        });
    }

    @OnClick(R.id.button5)
    public void button5() {
        mBankCardModel.defaultUserBankDetail("5", new HttpResultListener() {
            @Override
            public void onComplete() {
                super.onComplete();
                KLog.d(TAG, "defaultUserBankDetail complete");
            }
        });
    }

    @OnClick(R.id.button6)
    public void button6() {
        mUserAuthModel.userRealNameImageUpload("", new HttpOnNextListener<UserIdCardInfo>() {
            @Override
            public void onNext(UserIdCardInfo userIdCardInfo) {
                mUserIdCardInfo = userIdCardInfo;
                KLog.d(TAG, "id:" + userIdCardInfo.getCerNo() + " name:" + userIdCardInfo.getCerName());
            }
        });
    }

    @OnClick(R.id.button7)
    public void button7() {
        QYXUserEntity userInfo = new QYXUserEntity();
        userInfo.mobile = "13397380887";
        if (mUserIdCardInfo == null) {
//            Toasts.shortToast(this, "请先提交身份证认证！");
            mUserIdCardInfo = new UserIdCardInfo();
            mUserIdCardInfo.setCerNo("43250319930225282X");
            mUserIdCardInfo.setCerName("刘楼");
//            return;
        }
//        mUserAuthModel.userRealNameAuth(mUserIdCardInfo, new HttpResultListener() {
//            @Override
//            public void onComplete() {
//                super.onComplete();
//                Toasts.shortToast(TestActivity.this, "鉴权成功！");
//            }
//        });
    }

    @OnClick(R.id.button9)
    public void button9() {
        mUserAuthModel.userCreditVerify(new HttpOnNextListener<UserAuthInfo>() {
            @Override
            public void onNext(UserAuthInfo info) {
                Toasts.shortToast(TestActivity.this, info.toString());
            }
        });
    }

    @OnClick(R.id.button8)
    public void button8() {
        if (TextUtils.isEmpty(etCode.getText().toString().trim())) return;
        if (TextUtils.isEmpty(tradeNo) || TextUtils.isEmpty(wkPayNo)) return;
        mTranscationModel.checkCode(tradeNo, wkPayNo, etCode.getText().toString().trim(), new HttpResultListener() {
            @Override
            public void onComplete() {
                super.onComplete();
                Toasts.shortToast(TestActivity.this, "充值成功！");
            }
        });
    }

    @OnClick(R.id.button10)
    public void button10() {
        mTranscationModel.withdraw("10025", "14","", "",new HttpResultListener() {
            @Override
            public void onComplete() {
                super.onComplete();
                Toasts.shortToast(TestActivity.this, "提现成功");
            }
        });
    }

    @OnClick(R.id.button11)
    public void button11() {
        mBankCardModel.getTransBankList(AppConstant.TradeType.CHARHE, new HttpOnNextListener<TransBankCardList<BankCardInfo>>() {
            @Override
            public void onNext(TransBankCardList<BankCardInfo> transBankCardList) {
                KLog.d("transBankCardList--->" + transBankCardList.getIsOpenCredit() + " size-->" + transBankCardList.getBankCardList().size());
            }
        });
    }
}


